/**
 * Copyright (c) Martijn Grootens (m.e.grootens@student.utwente.nl), 
 * University of Twente.
 * Created july 2012.
 *
 * This file is part of dbcleaner.
 * 
 * dbcleaner is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * dbcleaner is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with dbcleaner.  If not, see <http://www.gnu.org/licenses/>.
 */

package dbcleaner.core.tags;

import java.io.*;
import java.util.*;

/**
 * Representation of a list of BibTeX tags (keywords). Basically just
 * an ArrayList of Tags
 */
public class TagList {

    // Name of the list.
    String name;
    
    // List of Tags.
    ArrayList<Tag> tags;
    
    /**
     * Constructor for a TagList with name.
     */
    public TagList (String name) {
        set_name(name);
        tags = new ArrayList<Tag>();
    }
    
    /**
     * Constructor nameless TagList.
     */
    public TagList () {
        this("no_name");
    }
    
    /**
     * Return name of this TagList.
     */
    public String get_name () {
        return name;
    }
    
    /**
     * Set TagList name.
     */
    public void set_name (String name) {
        this.name = name;
    }
    
    /**
     * Check if a Tag is present in this TagList.
     */
    public boolean contains (Tag t_search) {
        
        for (Tag t : tags)
            if (t.equals(t_search))
                return true;
        
        return false;
    }
    
    /**
     * Check if a String is present as a Tag
     */
    public boolean contains (String s_search) {
        
        for (Tag t : tags)
            if (t.equals(s_search))
                return true;
        
        return false;
    }
    
    /**
     * Return the Tag that corresponds with the String.
     * Return null if not present.
     */
    public Tag get_tag (String s) {
        
        for (Tag t : tags)
            if (t.equals(s))
                return t;
        
        return null;
    }
    
    /**
     * Add a Tag to the TagList.
     */
    public void add_tag (Tag t) {
        tags.add(t);
    }
    
    
    /**
     * Show info; for debugging.
     */
    public String show_info () {
        
        String ss = "TagList: \"" + get_name() + "\"\n";
        
        for (Tag t : tags)
            ss += t.show_info();
        
        return ss;
        
    }
    
    /**
     * Print the TagList.
     */
    public String toString () {
        
        String ss = "TagList: \"" + get_name() + "\"\n";
        
        for (Tag t : tags)
            ss += t;
        
        return ss;
        
    }
        

}